
<form  method="post" id="config_form" class="form-horizontal">
    <input type="hidden" name="id" value="{$privilege.id}">
    <div class="form-group">
        <label class="col-md-3 col-xs-12 control-label"></label>
        <div class="col-md-6 col-xs-12">
            <h2>二维码设置</h2>
        </div>
    </div>
    <div class="form-group">
        <label class="col-md-3 col-xs-12 control-label">客服二维码</label>
        <div class="col-md-6 col-xs-12">
            <input name="config[customer_qr_code]" type="text" id="customer_qr_code" class="form-control" value="{$config['customer_qr_code']}" readonly/>
            <button type="button" class="btn btn-block btn-info pull-right" data-id="customer_qr_code" onclick="uploadImageByObj(this)"> 上传 </button>
            <button type="button" class="btn btn-block btn-info pull-right" data-id="customer_qr_code" onclick="imageClick(this)"> 查看 </button>
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-3 col-xs-12 control-label">兑换二维码</label>
        <div class="col-md-6 col-xs-12">
            <input name="config[exchange_qr_code]" type="text" id="exchange_qr_code" class="form-control" value="{$config['exchange_qr_code']}" readonly/>
            <button type="button" class="btn btn-block btn-info pull-right" data-id="exchange_qr_code" onclick="uploadImageByObj(this)"> 上传 </button>
            <button type="button" class="btn btn-block btn-info pull-right" data-id="exchange_qr_code" onclick="imageClick(this)"> 查看 </button>
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-3 col-xs-12 control-label">领奖二维码</label>
        <div class="col-md-6 col-xs-12">
            <input name="config[accept_qr_code]" type="text" id="accept_qr_code" class="form-control" value="{$config['accept_qr_code']}" readonly/>
            <button type="button" class="btn btn-block btn-info pull-right" data-id="accept_qr_code" onclick="uploadImageByObj(this)"> 上传 </button>
            <button type="button" class="btn btn-block btn-info pull-right" data-id="accept_qr_code" onclick="imageClick(this)"> 查看 </button>
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-3 col-xs-12 control-label">裁判二维码</label>
        <div class="col-md-6 col-xs-12">
            <input name="config[referee_qr_code]" type="text" id="referee_qr_code" class="form-control" value="{$config['referee_qr_code']}" readonly/>
            <button type="button" class="btn btn-block btn-info pull-right" data-id="referee_qr_code" onclick="uploadImageByObj(this)"> 上传 </button>
            <button type="button" class="btn btn-block btn-info pull-right" data-id="referee_qr_code" onclick="imageClick(this)"> 查看 </button>
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-3 col-xs-12 control-label">申请代理客服二维码</label>
        <div class="col-md-6 col-xs-12">
            <input name="config[apply_agent_code]" type="text" id="apply_agent_code" class="form-control" value="{$config['apply_agent_code']}" readonly/>
            <button type="button" class="btn btn-block btn-info pull-right" data-id="apply_agent_code" onclick="uploadImageByObj(this)"> 上传 </button>
            <button type="button" class="btn btn-block btn-info pull-right" data-id="apply_agent_code" onclick="imageClick(this)"> 查看 </button>
        </div>
    </div>


    <div class="form-group">
        <label class="col-md-3 col-xs-12 control-label">推广二维码背景</label>
        <div class="col-md-6 col-xs-12">
            <input name="config[promotion_code_bg]" type="text" id="promotion_code_bg" class="form-control" value="{$config['promotion_code_bg']}" readonly/>
            <button type="button" class="btn btn-block btn-info pull-right" data-id="promotion_code_bg" onclick="uploadImageByObj(this)"> 上传 </button>
            <button type="button" class="btn btn-block btn-info pull-right" data-id="promotion_code_bg" onclick="imageClick(this)"> 查看 </button>
        </div>
    </div>

    <div>
        <div class="col-md-3 col-xs-12"></div>
        <div class="col-md-6 col-xs-12">
            <present name="errorNote">
                <div class="alert alert-danger" role="alert">
                    <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <strong>{$errorNote}</strong>
                </div>
            </present>
            <div class="form-group">
                <div class="col-md-6"><input type="reset" class="btn btn-block btn-default" value=" 清 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 空 " /></div>
                <div class="col-md-6"><button type="button" class="btn btn-block btn-info pull-right" onclick="edit()"> 提 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 交 </button></div>
            </div>
        </div>
    </div>
    <!-- Modal -->
    <div class="modal fade" id="hint_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="myModalLabel">提示</h4>
                </div>
                <div class="modal-body" id="hint_content">
                </div>
                <div class="modal-footer">
                    <button type="button" id="close_btn" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <!--<button type="button" class="btn btn-primary">Save changes</button>-->
                </div>
            </div>
        </div>
    </div>
</form>
<div class="modal fade" id="image_alert" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">二维码</h4>
            </div>
            <div class="modal-body" id="image_content">
                <img id="image_path" style="width: 100%"/>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <!--<button type="button" class="btn btn-primary">Save changes</button>-->
            </div>
        </div>
    </div>
</div>
<include file="Public:bootstrapUpload"/>
<script type="text/javascript">

    function uploadImageByObj(obj){
        var id = $(obj).data('id');
        var url = '__APP__/Admin/Public/upload';
//        uploadImage(id);
        initFileInput(id,url);
        $('#uploadModal').modal();
    }

    $(function () {
       var url = '__APP__/Admin/Public/upload';
       var controlName = 'importUserUrl';
        initFileInput(controlName,url);
    });

    function imageClick(obj) {
        var id = $(obj).data('id');
        var imageUrl = $('#'+id).val();
        $('#image_path').attr('src','__ROOT__/'+imageUrl);
        $('#image_alert').modal('show');
    }

    function edit() {
        $.ajax({
            type: "POST",
            url: "__URL__/edit",
            data:  $("#config_form").serialize(),
            dataType: "json",
            success: function (data) {
                console.info(data);
                $("#hint_content").empty().append(data.message);
                $("#hint_modal").modal();
            },
            error: function (data) {
                $("#hint_content").empty().append("请求超时！");
                $("#hint_modal").modal();
            }
        });
    }
</script>